﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using FrameworkManapro.BusinessModel;
using GMAC.ReportingSystem.Business.Entities;

namespace GMAC.ReportingSystem.DataAccess
{
    public class BankDataAccess : BaseDataAccess<Business.Entities.Bank>
    {
        # region Public Methods

        public override GMAC.ReportingSystem.Business.Entities.Bank Get(object id)
        {
            var parameters = new ArrayList() { id };
            var dt = DataAccessComponent.ExecuteSelect("procBanksByIdSelect", parameters);
            if (dt != null && dt.Rows.Count > 0)
                return ReadRow(dt.Rows[0]);
            return null;
        }

        /// <summary>
        /// Modified by: Michelle A. González A.
        /// Date:        27/07/2010
        /// Description: Added the CalculationType propiety.
        /// </summary>
        protected override GMAC.ReportingSystem.Business.Entities.Bank ReadRow(DataRow row)
        {
            Bank bank = null;
            if (row != null)
            {
                try
                {
                    bank = new Bank();
	                bank.DebitBankCode = int.Parse(row["DebitBankCode"].ToString());
	                bank.DebitBankName = row["DebitBankName"].ToString();
                    bank.DebitBankNumber = row["DebitBankNumber"].ToString();
	                bank.BankStatus = (bool)row["BankStatus"];
	                bank.BankEliminated = (bool)row["BankEliminated"];
                    if (!string.IsNullOrEmpty(row["BankId"].ToString()))
                    {
                        bank.BankId = int.Parse(row["BankId"].ToString());
                    }
	                
                }
                catch (Exception ex)
                {
                    throw;
                }
            }
            return bank;
        }

        protected override List<GMAC.ReportingSystem.Business.Entities.Bank> ReadTable(DataTable table)
        {
            var banks = new BankCollection();
            Bank bank;
            if (table != null && table.Rows.Count > 0)
            {
                try
                {
                    foreach (System.Data.DataRow row in table.Rows)
                    {
                        bank = ReadRow(row);
                        if (bank != null)
                        {
                            banks.Add(bank);
                        }
                    }
                }
                catch (Exception ex)
                {
                    throw;
                }
            }
            return banks;
        }

        //public BankCollection Search(string codeBank, string name, decimal? CostReceivable, string BankNumber, string CollectingAccount)
        //{
        //    ArrayList parameters = new ArrayList { codeBank, name, CostReceivable, BankNumber, CollectingAccount };
        //    DataTable dt = DataAccessComponent.ExecuteSelect("procBanksByFilterSelect", parameters);
        //    return ReadTable(dt) as BankCollection;
        //}

        public BankCollection GetList()
        {
            var dt = DataAccessComponent.ExecuteSelect("procBanksBySelect", null);
            return ReadTable(dt) as BankCollection;
        }
        //public BankCollection GetbyCode(string code)
        //{
        //    var parameters = new ArrayList() { code };
        //    var dt = DataAccessComponent.ExecuteSelect("procBanksBySelectCode", parameters);
        //    return ReadTable(dt) as BankCollection;
        //}

        //public BankCollection LoadBanksList(int productId, int? extractoutput)
        //{
        //    ArrayList parameters = new ArrayList { productId, extractoutput };
        //    DataTable dt = DataAccessComponent.ExecuteSelect("procBanksList", parameters);
        //    return ReadTable(dt) as BankCollection;
        //}
        //public Bank GetbyBankNumber(string DebitAccountNumber)
        //{
        //    var parameters = new ArrayList() { DebitAccountNumber };
        //    var dt = DataAccessComponent.ExecuteSelect("procBanksGetbyBankNumber", parameters);
        //    return ReadRow(dt.Rows[0]) as Bank;
        //}

        #endregion
    }
}
